﻿namespace DslEditorPowerToy.Controls.Languages.ToolWindows
{
    using Microsoft.VisualStudio.Modeling.Shell;
    using System;

    [CLSCompliant(false)]
    public abstract class DslLanguageBase : ToolWindow
    {
        private ModelingDocView _docView;
        private Type _docViewType;

        public DslLanguageBase(IServiceProvider serviceProvider, Type dslLanguageDocViewType) : base(serviceProvider)
        {
            this._docViewType = dslLanguageDocViewType;
        }

        protected override void OnDocumentWindowChanged(ModelingDocView oldView, ModelingDocView newView)
        {
            base.OnDocumentWindowChanged(oldView, newView);
            this._docView = null;
            if (newView != null)
            {
                if ((this._docViewType != null) && (newView.GetType() == this._docViewType))
                {
                    this._docView = newView;
                }
            }
            else if (newView != null)
            {
                base.Hide();
            }
        }

        protected ModelingDocView DocView
        {
            get
            {
                return this._docView;
            }
        }

        protected override bool EnableUndo
        {
            get
            {
                return true;
            }
        }
    }
}

